import random
import matplotlib.pyplot as plt
plt.rcParams['font.family'] = 'sans-serif'
plt.rcParams['font.sans-serif'] = ['SimHei']
def roll_dice(num_rolls):
    results = {}
    for _ in range(num_rolls):
        roll = random.randint(1,6)
        if roll in results:
            results[roll] += 1
        else:
            results[roll] = 1
    return results
num_rolls = 100
results  = roll_dice(num_rolls)
dice_values = list(results.keys())
frequencies = list(results.values())
plt.bar(dice_values,frequencies)
plt.xlabel('骰子点数')
plt.ylabel('频率')
plt.title('投掷骰子100次结果')
plt.show()